﻿using Basic.HrGatewayModular.Interface;
using Basic.HrRemoteModel.Dic;
using Basic.HrRemoteModel.Dic.Model;
using WeDonekRpc.Helper;
using WeDonekRpc.Model;

namespace Basic.HrGatewayModular.Services
{
    internal class DicService : IDicService
    {
        public long AddDic ( DicAdd datum )
        {
            return new AddDic
            {
                Datum = datum,
            }.Send();
        }

        public void DeleteDic ( long id )
        {
            new DeleteDic
            {
                Id = id,
            }.Send();
        }

        public bool EnableDic ( long id )
        {
            return new EnableDic
            {
                Id = id,
            }.Send();
        }

        public DicDto GetDic ( long id )
        {
            return new GetDic
            {
                Id = id,
            }.Send();
        }

        public DicIKeyVal[] GetItems ( bool? isTree )
        {
            DicIKeyVal[] vals = new GetDicList().Send();
            if ( isTree.HasValue )
            {
                return vals.FindAll(c => c.IsTreeDic == isTree.Value);
            }
            return vals;
        }

        public string GetName ( long id )
        {
            return new GetDicName
            {
                Id = id,
            }.Send();
        }

        public DicDatum[] QueryDic ( DicQuery query, IBasicPage paging, out int count )
        {
            return new QueryDic
            {
                Query = query,
                Index = paging.Index,
                Size = paging.Size,
                NextId = paging.NextId,
                SortName = paging.SortName,
                IsDesc = paging.IsDesc
            }.Send(out count);
        }

        public bool SetDic ( long id, DicSet datum )
        {
            return new SetDic
            {
                Id = id,
                Datum = datum,
            }.Send();
        }

        public bool StopDic ( long id )
        {
            return new StopDic
            {
                Id = id,
            }.Send();
        }

    }
}
